﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ServiceQuestions : AppServices
{
    private List<ProxyWrapper.CommonProxyService.Questions> _qDetails = null;
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            try
            {
                string usersList = Request["selectedUsers[]"] != null ? Request["selectedUsers[]"].ToString() : "";// SrvDetails.ServiceName;            
                if (usersList.Trim().Length > 0)
                {
                    ProxyWrapper.UserServiceWrapper _usrWrapper = new ProxyWrapper.UserServiceWrapper();
                    _usrWrapper.AssociateServiceToUsers(UserDetails, ServiceId, usersList);
                }
            }
            catch (Exception)
            {

            }
            finally
            {
                DrawPage();
            }

        }
    }

    private void DrawPage()
    {

    }

    protected string GetAvailableQuestions()
    {
        Object[] arrId = null;
        ProxyWrapper.QuestionsServiceWrapper _qWrapper = new ProxyWrapper.QuestionsServiceWrapper();
        _qDetails = new List<ProxyWrapper.CommonProxyService.Questions>();
        _qDetails = _qWrapper.GetQuestionsList(UserDetails.UserId, UserDetails.HashCode);
        if(SrvDetails!=null && SrvDetails.ServiceQuestions!=null && SrvDetails.ServiceQuestions.Length>0)
        {
             arrId = new Object[SrvDetails.ServiceQuestions.Length];
        for (int i = 0; i < SrvDetails.ServiceQuestions.Length; i++)
        {
            arrId[i] = SrvDetails.ServiceQuestions[i].QuestionId;
        }
        }
        string questionsText = "<li class='q_order_li'>" +
                                       "<span class='draghandle mobile_disabled'>&nbsp;</span><span class='q_{0}'>&nbsp;</span><span class='dragmove'>&nbsp;</span><span class='dragmoveu'>&nbsp;</span><span class='dragmovedown'>&nbsp;</span><span class='dragmoveside'>&nbsp;</span><span class='q_edit mobile_disable'>&nbsp;</span><input type='hidden' class='inputcheckbox' value='{1}' /><label class='dragtext'>{2}</label><div class=q_info' style='display: none;'>Question Type:{3}</div>" +
                                   "</li>";
        StringBuilder sb = new StringBuilder();
        object[] ob = new object[4];
        for (int i = 0; i < _qDetails.Count; i++)
        {
            if (arrId ==null || !arrId.Contains(_qDetails[i].QuestionId))
            {
                ob[0] = _qDetails[i].QuestionSubType;
                ob[1] = _qDetails[i].QuestionId;
                ob[2] = _qDetails[i].QuestionText;
                ob[3] = _qDetails[i].QuestionSubType;
                sb.Append(string.Format(questionsText, ob));
            }
        }
        return sb.ToString();
    }

    protected string GetSelectedQuestions(Enums.QuestionsType type)
    {
        StringBuilder sbPre = new StringBuilder();
        StringBuilder sbPost = new StringBuilder();
        StringBuilder sbValid = new StringBuilder();
        StringBuilder sbInvalid = new StringBuilder();
        switch (type)
        {
            case Enums.QuestionsType.pre:

                if (SrvDetails.ServiceQuestions != null && SrvDetails.ServiceQuestions.Length > 0)
                {
                    for (int i = 0; i < SrvDetails.ServiceQuestions.Length; i++)
                    {
                        if (SrvDetails.ServiceQuestions[i].IsBeforSubmittingScan)
                        {
                            sbPre.Append("<li class='q_order_li' style='display: block;'>");
                            sbPre.Append("<span class='draghandle mobile_disabled'>&nbsp;</span>");
                            sbPre.Append("<span class='q_checkbox'>&nbsp;</span>");
                            sbPre.Append("<span class='dragmove'>&nbsp;</span>");
                            sbPre.Append("<span class='dragmoveu'>&nbsp;</span>");
                            sbPre.Append("<span class='dragmovedown'>&nbsp;</span>");
                            sbPre.Append("<span class='dragmoveside'>&nbsp;</span>");
                            sbPre.Append("<span class='q_edit mobile_disable'>&nbsp;</span>");
                            sbPre.Append("<input type='hidden' class='inputcheckbox' value="+SrvDetails.ServiceQuestions[i].QuestionId.ToString()+">");
                            sbPre.Append("<label class='dragtext'>"+SrvDetails.ServiceQuestions[i].QuestionText+"</label>");
                            sbPre.Append("<div class='q_info' style='display: none;'>Question Type:" + SrvDetails.ServiceQuestions[i].QuestionType+ "</div></li>");
                        }
                    }
                    if (sbPre.Length > 0)
                        sbPre.Insert(0, "<li class='dragempty nodrag' style='display: none;'>Drag To Here</li>");
                }
                else
                {
                    sbPre.Append("<li class='dragempty nodrag' style='display: block;'>Drag To Here</li>");
                }
                return sbPre.ToString();
            case Enums.QuestionsType.post:
                if (SrvDetails.ServiceQuestions != null && SrvDetails.ServiceQuestions.Length > 0)
                {
                    for (int i = 0; i < SrvDetails.ServiceQuestions.Length ; i++)
                    {
                        if (SrvDetails.ServiceQuestions[i].IsAfterSubmittingScan)
                        {
                            sbPost.Append("<li class='q_order_li' style='display: block;'>");
                            sbPost.Append("<span class='draghandle mobile_disabled'>&nbsp;</span>");
                            sbPost.Append("<span class='q_checkbox'>&nbsp;</span>");
                            sbPost.Append("<span class='dragmove'>&nbsp;</span>");
                            sbPost.Append("<span class='dragmoveu'>&nbsp;</span>");
                            sbPost.Append("<span class='dragmovedown'>&nbsp;</span>");
                            sbPost.Append("<span class='dragmoveside'>&nbsp;</span>");
                            sbPost.Append("<span class='q_edit mobile_disable'>&nbsp;</span>");
                            sbPost.Append("<input type='hidden' class='inputcheckbox' value=" + SrvDetails.ServiceQuestions[i].QuestionId.ToString() + ">");
                            sbPost.Append("<label class='dragtext'>" + SrvDetails.ServiceQuestions[i].QuestionText + "</label>");
                            sbPost.Append("<div class='q_info' style='display: none;'>Question Type:" + SrvDetails.ServiceQuestions[i].QuestionType + "</div></li>");
                        }
                    }
                    if (sbPost.Length > 0)
                        sbPost.Insert(0, "<li class='dragempty nodrag' style='display: none;'>Drag To Here</li>");
                }
                else
                {
                    sbPost.Append("<li class='dragempty nodrag' style='display: block;'>Drag To Here</li>");
                }                
                return sbPost.ToString();
            case Enums.QuestionsType.valid:
                if (SrvDetails.ServiceQuestions != null && SrvDetails.ServiceQuestions.Length > 0)
                {
                    for (int i = 0; i < SrvDetails.ServiceQuestions.Length; i++)
                    {
                        if (SrvDetails.ServiceQuestions[i].IsSubmittingValidScan)
                        {
                            sbValid.Append("<li class='q_order_li' style='display: block;'>");
                            sbValid.Append("<span class='draghandle mobile_disabled'>&nbsp;</span>");
                            sbValid.Append("<span class='q_checkbox'>&nbsp;</span>");
                            sbValid.Append("<span class='dragmove'>&nbsp;</span>");
                            sbValid.Append("<span class='dragmoveu'>&nbsp;</span>");
                            sbValid.Append("<span class='dragmovedown'>&nbsp;</span>");
                            sbValid.Append("<span class='dragmoveside'>&nbsp;</span>");
                            sbValid.Append("<span class='q_edit mobile_disable'>&nbsp;</span>");
                            sbValid.Append("<input type='hidden' class='inputcheckbox' value=" + SrvDetails.ServiceQuestions[i].QuestionId.ToString() + ">");
                            sbValid.Append("<label class='dragtext'>" + SrvDetails.ServiceQuestions[i].QuestionText + "</label>");
                            sbValid.Append("<div class='q_info' style='display: none;'>Question Type:" + SrvDetails.ServiceQuestions[i].QuestionType + "</div></li>");
                        }
                    }
                    if (sbValid.Length > 0)
                        sbValid.Insert(0, "<li class='dragempty nodrag' style='display: none;'>Drag To Here</li>");
                }
                else
                {
                    sbValid.Append("<li class='dragempty nodrag' style='display: block;'>Drag To Here</li>");
                }                    
                return sbValid.ToString();
            case Enums.QuestionsType.invalid:
                if (SrvDetails.ServiceQuestions != null && SrvDetails.ServiceQuestions.Length > 0)
                {
                    for (int i = 0; i < SrvDetails.ServiceQuestions.Length; i++)
                    {
                        if (SrvDetails.ServiceQuestions[i].IsSubmittingInValidScan)
                        {
                            sbInvalid.Append("<li class='q_order_li' style='display: block;'>");
                            sbInvalid.Append("<span class='draghandle mobile_disabled'>&nbsp;</span>");
                            sbInvalid.Append("<span class='q_checkbox'>&nbsp;</span>");
                            sbInvalid.Append("<span class='dragmove'>&nbsp;</span>");
                            sbInvalid.Append("<span class='dragmoveu'>&nbsp;</span>");
                            sbInvalid.Append("<span class='dragmovedown'>&nbsp;</span>");
                            sbInvalid.Append("<span class='dragmoveside'>&nbsp;</span>");
                            sbInvalid.Append("<span class='q_edit mobile_disable'>&nbsp;</span>");
                            sbInvalid.Append("<input type='hidden' class='inputcheckbox' value=" + SrvDetails.ServiceQuestions[i].QuestionId.ToString() + ">");
                            sbInvalid.Append("<label class='dragtext'>" + SrvDetails.ServiceQuestions[i].QuestionText + "</label>");
                            sbInvalid.Append("<div class='q_info' style='display: none;'>Question Type:" + SrvDetails.ServiceQuestions[i].QuestionType + "</div></li>");
                        }
                    }
                    if (sbInvalid.Length > 0)
                        sbInvalid.Insert(0, "<li class='dragempty nodrag' style='display: none;'>Drag To Here</li>");
                }
                else
                {
                    sbInvalid.Append("<li class='dragempty nodrag' style='display: block;'>Drag To Here</li>");
                } 
                return sbInvalid.ToString();
            default:
                return "";
        }
    }
}